<!DOCTYPE html>
<html lang="en" xmlns:sa="http://www.thymeleaf.org/extras/sa-token"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>电信备案管理</title>
    <!--公共模块-->
    <div th:replace="~{layout}"></div>
</head>
<body>
<div class="panel panel-default operation_telecom" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form class="layui-form" action="" lay-filter="info" style="width: 900px;margin-top: 10px">
            <input name="id" hidden/>
            
            <!-- 第一行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>主端口号</label>
                        <div class="layui-input-block">
                            <input type="number" name="mainPort" placeholder="请输入主端口号(1-65535)" autocomplete="off" class="layui-input" lay-verify="required|number" min="1" max="65535">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>子端口号</label>
                        <div class="layui-input-block">
                            <input type="number" name="subPort" placeholder="请输入子端口号(1-65535)" autocomplete="off" class="layui-input" lay-verify="required|number" min="1" max="65535">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第二行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>业务类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="businessType" placeholder="请输入业务类型" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>授权书</label>
                        <div class="layui-input-block">
                            <input type="text" name="authorizationFileUrl" placeholder="请输入授权书URL" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第三行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>授权书开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="authStartTime" id="authStartTime" placeholder="请选择授权书开始时间" autocomplete="off" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>授权书结束时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="authEndTime" id="authEndTime" placeholder="请选择授权书结束时间" autocomplete="off" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第四行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>具体用途</label>
                        <div class="layui-input-block">
                            <textarea name="usageDetail" placeholder="请输入具体用途" class="layui-textarea" lay-verify="required"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>企业名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="companyName" placeholder="请输入企业名称" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第五行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>企业统一社会信用代码</label>
                        <div class="layui-input-block">
                            <input type="text" name="companyUscc" placeholder="请输入企业统一社会信用代码(18位)" autocomplete="off" class="layui-input" lay-verify="required|uscc" maxlength="18">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>责任人(含法人)</label>
                        <div class="layui-input-block">
                            <input type="text" name="responsiblePerson" placeholder="请输入责任人姓名" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第六行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>法人证件类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="legalIdType" placeholder="请输入法人证件类型" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>法人证件号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="legalIdNumber" placeholder="请输入法人证件号码" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第七行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>经办人名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="agentName" placeholder="请输入经办人名称" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>经办人证件类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="agentIdType" placeholder="请输入经办人证件类型" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第八行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>经办人证件号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="agentIdNumber" placeholder="请输入经办人证件号码" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>基础电信企业ID</label>
                        <div class="layui-input-block">
                            <input type="text" name="telcoEnterpriseId" placeholder="请输入基础电信企业ID" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第九行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>运营商接入机房位置与设备位置</label>
                        <div class="layui-input-block">
                            <textarea name="carrierRoomAndDeviceLocation" placeholder="请输入运营商接入机房位置与设备位置" class="layui-textarea" lay-verify="required"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>短信端口企业商接入机房位置与设备位置</label>
                        <div class="layui-input-block">
                            <textarea name="smsPortEnterpriseRoomAndDeviceLocation" placeholder="请输入短信端口企业商接入机房位置与设备位置" class="layui-textarea" lay-verify="required"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>子端口签名</label>
                        <div class="layui-input-block">
                            <input type="text" name="subPortSignature" placeholder="请输入子端口签名" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">接入机房及设备</label>
                        <div class="layui-input-block">
                            <textarea name="accessRoomAndDevice" placeholder="请输入接入机房及设备" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十一行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属地区</label>
                        <div class="layui-input-block">
                            <input type="text" name="region" placeholder="请输入所属地区" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否绿色通道</label>
                        <div class="layui-input-block">
                            <select name="greenChannel">
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十二行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否签名校验</label>
                        <div class="layui-input-block">
                            <select name="signatureVerify">
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">黑白名单</label>
                        <div class="layui-input-block">
                            <input type="text" name="blackWhiteList" placeholder="请输入黑白名单" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十三行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">责任人身份证正面附件</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="respIdFrontUpload">上传图片</button>
                                <input type="hidden" name="respIdFrontUrl" id="respIdFrontUrl">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="respIdFrontPreview" style="max-width: 200px; max-height: 150px; display: none;">
                                    <p id="respIdFrontText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">责任人身份证反面附件</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="respIdBackUpload">上传图片</button>
                                <input type="hidden" name="respIdBackUrl" id="respIdBackUrl">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="respIdBackPreview" style="max-width: 200px; max-height: 150px; display: none;">
                                    <p id="respIdBackText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十四行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">经办人身份证正面附件</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="agentIdFrontUpload">上传图片</button>
                                <input type="hidden" name="agentIdFrontUrl" id="agentIdFrontUrl">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="agentIdFrontPreview" style="max-width: 200px; max-height: 150px; display: none;">
                                    <p id="agentIdFrontText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">经办人身份证反面附件</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="agentIdBackUpload">上传图片</button>
                                <input type="hidden" name="agentIdBackUrl" id="agentIdBackUrl">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="agentIdBackPreview" style="max-width: 200px; max-height: 150px; display: none;">
                                    <p id="agentIdBackText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十五行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">单位授权书附件</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="companyAuthFileUpload">上传图片</button>
                                <input type="hidden" name="companyAuthFileUrl" id="companyAuthFileUrl">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="companyAuthFilePreview" style="max-width: 200px; max-height: 150px; display: none;">
                                    <p id="companyAuthFileText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">经办人现场照片</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="agentLivePhotoUpload">上传图片</button>
                                <input type="hidden" name="agentLivePhotoUrl" id="agentLivePhotoUrl">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="agentLivePhotoPreview" style="max-width: 200px; max-height: 150px; display: none;">
                                    <p id="agentLivePhotoText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十六行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">端口审核表</label>
                        <div class="layui-input-block">
                            <input type="text" name="portAuditFormUrl" placeholder="请输入端口审核表URL" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>端口入网时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="portNetworkTime" id="portNetworkTime" placeholder="请选择端口入网时间" autocomplete="off" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十七行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>单位证件类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="companyCertType" placeholder="请输入单位证件类型" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">责任人证件地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="respIdAddress" placeholder="请输入责任人证件地址" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十八行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">经办人证件地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="agentIdAddress" placeholder="请输入经办人证件地址" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>短信模板</label>
                        <div class="layui-input-block">
                            <textarea name="smsTemplate" placeholder="请输入短信模板" class="layui-textarea" lay-verify="required"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十九行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">身份信息三要素秘钥</label>
                        <div class="layui-input-block">
                            <input type="text" name="identity3ElementsKey" placeholder="请输入身份信息三要素秘钥" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>业务大类</label>
                        <div class="layui-input-block">
                            <input type="text" name="bizCategory" placeholder="请输入业务大类" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第二十行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>业务细类</label>
                        <div class="layui-input-block">
                            <input type="text" name="bizSubcategory" placeholder="请输入业务细类" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">协议合同文本</label>
                        <div class="layui-input-block">
                            <input type="text" name="agreementContractUrl" placeholder="请输入协议合同文本URL" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第二十一行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">营业执照</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="businessLicenseUpload">上传图片</button>
                                <input type="hidden" name="businessLicenseUrl" id="businessLicenseUrl">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="businessLicensePreview" style="max-width: 200px; max-height: 150px; display: none;">
                                    <p id="businessLicenseText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">事业单位法人证书复印件</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="institutionLegalCopyUpload">上传图片</button>
                                <input type="hidden" name="institutionLegalCopyUrl" id="institutionLegalCopyUrl">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="institutionLegalCopyPreview" style="max-width: 200px; max-height: 150px; display: none;">
                                    <p id="institutionLegalCopyText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第二十二行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>端口类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="portType" placeholder="请输入端口类型" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <select name="status">
                                <option value="0">待提交</option>
                                <option value="1">已提交</option>
                                <option value="2">已备案</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                    <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="telecom_table_div">
    <div id="searchParam">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="text" name="companyName" class="layui-input" autocomplete="off" placeholder="请输入公司名称">
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="businessType" class="layui-input" autocomplete="off" placeholder="请输入业务类型">
                </div>
                <div class="layui-input-inline layui-form">
                    <select name="status">
                        <option value="">请选择状态</option>
                        <option value="0">待提交</option>
                        <option value="1">已提交</option>
                        <option value="2">已备案</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                </div>
            </div>
        </form>
    </div>
    
    <table class="layui-hide" id="telecom_table" lay-filter="telecom_table"></table>
</div>

<!-- 隐藏的文件上传输入框 -->
<input type="file" id="importFile" accept=".xlsx,.xls" style="display: none;">

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addNewTelecom">新增</button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="importData">导入</button>
        <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="refreshData">刷新</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="batchToPending">批量待提交</button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="batchToSubmitted">批量已提交</button>
        <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="batchToFiled">批量已备案</button>
    </div>
</script>

<script type="text/html" id="tool">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="toPending">待提交</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="toSubmitted">已提交</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="toFiled">已备案</a>
</script>

<script type="text/html" id="statusTpl">
    {{# if(d.status == 0) { }}
        <span class="layui-badge layui-bg-orange">待提交</span>
    {{# } else if(d.status == 1) { }}
        <span class="layui-badge layui-bg-blue">已提交</span>
    {{# } else if(d.status == 2) { }}
        <span class="layui-badge layui-bg-green">已备案</span>
    {{# } else { }}
        <span class="layui-badge layui-bg-gray">未知</span>
    {{# } }}
</script>

<script th:inline="none">
            layui.use(['table', 'form', 'layer', 'laydate'], function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;

            // 自定义验证规则
            form.verify({
                uscc: function(value, item) {
                    if (value && value.length > 18) {
                        return '企业统一社会信用代码不能超过18位';
                    }
                    // 统一社会信用代码格式验证：18位，由数字和大写字母组成
                    /*if (value && !/^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/.test(value)) {
                        return '请输入正确的企业统一社会信用代码格式';
                    }*/
                }
            });

        var tableIns = table.render({
            elem: '#telecom_table'
            , contentType: 'application/json'
            , page: true
            , url: ctx + 'telecomRecord/listByPage'
            , method: 'POST'
            , parseData: function (res) {
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": res.data ? res.data.total : 0,
                    "data": res.data ? res.data.records : []
                }
            }
            , cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'mainPort', title: '主端口', width: 120},
                    {field: 'subPort', title: '子端口', width: 120},
                    {field: 'businessType', title: '业务类型', width: 100},
                    {field: 'companyName', title: '公司名称', width: 200},
                    {field: 'responsiblePerson', title: '负责人', width: 100},
                    {field: 'status', title: '状态', width: 100, templet: '#statusTpl'},
                    {field: 'createTime', title: '创建时间', width: 160},
                    {field: 'updateTime', title: '更新时间', width: 160},
                    {title: '操作', width: 350, toolbar: '#tool', fixed: 'right'}
                ]
            ]
            , toolbar: '#toolbar'
        });

        // 初始化日期选择器
        laydate.render({
            elem: '#authStartTime'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#authEndTime'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#portNetworkTime'
            , type: 'datetime'
        });

        // 工具栏事件
        table.on('toolbar(telecom_table)', function (obj) {
            switch (obj.event) {
                case 'addNewTelecom':
                    $(".telecom_table_div").hide();
                    $(".operation_telecom").show();
                    $(".title").html("新增电信备案");
                    form.val('info', {
                        "id": "",
                        "mainPort": "",
                        "subPort": "",
                        "businessType": "",
                        "authorizationFileUrl": "",
                        "authStartTime": "",
                        "authEndTime": "",
                        "usageDetail": "",
                        "companyName": "",
                        "companyUscc": "",
                        "responsiblePerson": "",
                        "legalIdType": "",
                        "legalIdNumber": "",
                        "agentName": "",
                        "agentIdType": "",
                        "agentIdNumber": "",
                        "telcoEnterpriseId": "",
                        "carrierRoomAndDeviceLocation": "",
                        "smsPortEnterpriseRoomAndDeviceLocation": "",
                        "subPortSignature": "",
                        "accessRoomAndDevice": "",
                        "region": "",
                        "greenChannel": "",
                        "signatureVerify": "",
                        "blackWhiteList": "",
                        "respIdFrontUrl": "",
                        "respIdBackUrl": "",
                        "agentIdFrontUrl": "",
                        "agentIdBackUrl": "",
                        "companyAuthFileUrl": "",
                        "agentLivePhotoUrl": "",
                        "portAuditFormUrl": "",
                        "portNetworkTime": "",
                        "companyCertType": "",
                        "respIdAddress": "",
                        "agentIdAddress": "",
                        "smsTemplate": "",
                        "identity3ElementsKey": "",
                        "bizCategory": "",
                        "bizSubcategory": "",
                        "agreementContractUrl": "",
                        "businessLicenseUrl": "",
                        "institutionLegalCopyUrl": "",
                        "portType": "",
                        "status": "0"
                    });
                    
                    // 清空图片预览
                    clearImagePreviews();
                    
                    // 新增时移除子端口号的只读属性
                    $('input[name="subPort"]').removeAttr('readonly');
                    
                    // 重新初始化上传功能
                    initImageUpload();
                    
                    // 重新渲染表单
                    form.render();
                    break;
                case 'importData':
                    document.getElementById('importFile').click();
                    break;
                case 'refreshData':
                    tableIns.reload();
                    break;
                case 'batchToPending':
                    batchUpdateStatus(table.checkStatus('telecom_table').data, 0);
                    break;
                case 'batchToSubmitted':
                    batchUpdateStatus(table.checkStatus('telecom_table').data, 1);
                    break;
                case 'batchToFiled':
                    batchUpdateStatus(table.checkStatus('telecom_table').data, 2);
                    break;
            }
        });

        // 行工具事件
        table.on('tool(telecom_table)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    layer.confirm('确定删除这条记录吗？', {icon: 3, title: '提示'}, function (index) {
                        layer.close(index);
                        CoreUtil.sendDelete(ctx + 'telecomRecord/delete/' + data.id, null, function (res) {
                            layer.msg(res.msg);
                            tableIns.reload();
                        });
                    });
                    break;
                case 'edit':
                    $(".telecom_table_div").hide();
                    $(".operation_telecom").show();
                    $(".title").html("编辑电信备案");
                    getTelecomDetail(data.id);
                    break;
                case 'toPending':
                    updateStatus(data.id, 0, '待提交');
                    break;
                case 'toSubmitted':
                    updateStatus(data.id, 1, '已提交');
                    break;
                case 'toFiled':
                    updateStatus(data.id, 2, '已备案');
                    break;
            }
        });

        // 获取详情
        var getTelecomDetail = function (id) {
            CoreUtil.sendGet(ctx + "telecomRecord/detail/" + id, null, function (res) {
                if (res.code === 0) {
                    form.val('info', res.data);
                    
                    // 显示已有的图片
                    showExistingImages(res.data);
                    
                    // 编辑时设置子端口号为只读
                    $('input[name="subPort"]').attr('readonly', true);
                    
                    // 重新初始化上传功能
                    initImageUpload();
                } else {
                    layer.msg('获取详情失败：' + res.msg);
                }
            });
        };

        // 显示已有的图片
        var showExistingImages = function (data) {
            // 责任人身份证正面附件
            if (data.respIdFrontUrl) {
                var imageUrl = data.respIdFrontUrl.startsWith('http') ? data.respIdFrontUrl : 'http://localhost:8004' + data.respIdFrontUrl;
                $('#respIdFrontPreview').attr('src', imageUrl).show();
                $('#respIdFrontText').html('<span style="color: #5FB878;">已上传</span>');
            }
            
            // 责任人身份证反面附件
            if (data.respIdBackUrl) {
                var imageUrl = data.respIdBackUrl.startsWith('http') ? data.respIdBackUrl : 'http://localhost:8004' + data.respIdBackUrl;
                $('#respIdBackPreview').attr('src', imageUrl).show();
                $('#respIdBackText').html('<span style="color: #5FB878;">已上传</span>');
            }
            
            // 经办人身份证正面附件
            if (data.agentIdFrontUrl) {
                var imageUrl = data.agentIdFrontUrl.startsWith('http') ? data.agentIdFrontUrl : 'http://localhost:8004' + data.agentIdFrontUrl;
                $('#agentIdFrontPreview').attr('src', imageUrl).show();
                $('#agentIdFrontText').html('<span style="color: #5FB878;">已上传</span>');
            }
            
            // 经办人身份证反面附件
            if (data.agentIdBackUrl) {
                var imageUrl = data.agentIdBackUrl.startsWith('http') ? data.agentIdBackUrl : 'http://localhost:8004' + data.agentIdBackUrl;
                $('#agentIdBackPreview').attr('src', imageUrl).show();
                $('#agentIdBackText').html('<span style="color: #5FB878;">已上传</span>');
            }
            
            // 单位授权书附件
            if (data.companyAuthFileUrl) {
                var imageUrl = data.companyAuthFileUrl.startsWith('http') ? data.companyAuthFileUrl : 'http://localhost:8004' + data.companyAuthFileUrl;
                $('#companyAuthFilePreview').attr('src', imageUrl).show();
                $('#companyAuthFileText').html('<span style="color: #5FB878;">已上传</span>');
            }
            
            // 经办人现场照片
            if (data.agentLivePhotoUrl) {
                var imageUrl = data.agentLivePhotoUrl.startsWith('http') ? data.agentLivePhotoUrl : 'http://localhost:8004' + data.agentLivePhotoUrl;
                $('#agentLivePhotoPreview').attr('src', imageUrl).show();
                $('#agentLivePhotoText').html('<span style="color: #5FB878;">已上传</span>');
            }
            
            // 营业执照
            if (data.businessLicenseUrl) {
                var imageUrl = data.businessLicenseUrl.startsWith('http') ? data.businessLicenseUrl : 'http://localhost:8004' + data.businessLicenseUrl;
                $('#businessLicensePreview').attr('src', imageUrl).show();
                $('#businessLicenseText').html('<span style="color: #5FB878;">已上传</span>');
            }
            
            // 事业单位法人证书复印件
            if (data.institutionLegalCopyUrl) {
                var imageUrl = data.institutionLegalCopyUrl.startsWith('http') ? data.institutionLegalCopyUrl : 'http://localhost:8004' + data.institutionLegalCopyUrl;
                $('#institutionLegalCopyPreview').attr('src', imageUrl).show();
                $('#institutionLegalCopyText').html('<span style="color: #5FB878;">已上传</span>');
            }
        };

        // 清空图片预览
        var clearImagePreviews = function () {
            // 清空所有图片预览
            $('.layui-upload-img').hide().attr('src', '');
            $('.layui-upload-list p').html('');
            
            // 清空隐藏的URL输入框
            $('input[name$="Url"]').val('');
        };

        // 更新状态
        var updateStatus = function (id, status, statusName) {
            var url = '';
            switch (status) {
                case 0:
                    url = 'telecomRecord/status/toPending/' + id;
                    break;
                case 1:
                    url = 'telecomRecord/status/toSubmitted/' + id;
                    break;
                case 2:
                    url = 'telecomRecord/status/toFiled/' + id;
                    break;
            }
            
            CoreUtil.sendPost(ctx + url, null, function (res) {
                layer.msg(res.msg);
                tableIns.reload();
            });
        };

        // 批量更新状态
        var batchUpdateStatus = function (data, status) {
            var ids = [];
            for (var i = 0; i < data.length; i++) {
                ids.push(data[i].id);
            }

            if (ids.length === 0) {
                layer.msg('请选择要批量操作的记录');
                return;
            }

            var statusName = '';
            switch (status) {
                case 0:
                    statusName = '待提交';
                    break;
                case 1:
                    statusName = '已提交';
                    break;
                case 2:
                    statusName = '已备案';
                    break;
            }

            layer.confirm('确定要将选中的 ' + ids.length + ' 条记录设置为 "' + statusName + '" 吗？', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                CoreUtil.sendPost(ctx + 'telecomRecord/status/batchUpdateStatus', {ids: ids, status: status}, function (res) {
                    layer.msg(res.msg);
                    tableIns.reload();
                });
            });
        };

        // 返回按钮
        $("#btn_cancel").click(function () {
            $(".telecom_table_div").show();
            $(".operation_telecom").hide();
            return false;
        });

        // 监听提交
        form.on('submit(submit)', function (data) {
            var params = data.field;
            
            if (params.id === undefined || params.id === null || params.id === "") {
                // 新增
                CoreUtil.sendPost(ctx + "telecomRecord/add", params, function (res) {
                    layer.msg(res.msg);
                    $(".telecom_table_div").show();
                    $(".operation_telecom").hide();
                    tableIns.reload();
                });
            } else {
                // 编辑
                CoreUtil.sendPost(ctx + "telecomRecord/update", params, function (res) {
                    layer.msg(res.msg);
                    $(".telecom_table_div").show();
                    $(".operation_telecom").hide();
                    tableIns.reload();
                });
            }
            return false;
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            tableIns.reload({
                page: {
                    curr: 1
                }
                , where: data.field
            });
            return false;
        });

        // 文件导入处理
        document.getElementById('importFile').onchange = function (e) {
            var file = e.target.files[0];
            if (!file) {
                return;
            }

            var formData = new FormData();
            formData.append('file', file);

            layer.load(1, {shade: [0.3, '#000']});

            fetch(ctx + 'telecomRecord/import', {
                method: 'POST',
                body: formData
            }).then(response => response.json()).then(result => {
                layer.closeAll('loading');
                if (result.code === 0) {
                    layer.msg('导入成功', {icon: 1});
                    tableIns.reload();
                } else {
                    layer.msg('导入失败：' + result.msg, {icon: 2});
                }
            }).catch(err => {
                layer.closeAll('loading');
                layer.msg('导入失败：' + err.message, {icon: 2});
            });

            e.target.value = '';
        };

        // 图片上传功能 - 使用input[type="file"]方式
        function initImageUpload() {
            // 为每个上传按钮创建隐藏的文件输入框
            $('[id$="Upload"]').each(function() {
                var uploadId = $(this).attr('id');
                var fieldId = uploadId.replace('Upload', '');
                
                // 创建隐藏的文件输入框
                var fileInput = $('<input type="file" id="' + fieldId + 'File" accept="image/*" style="display: none;">');
                $(this).after(fileInput);
                
                // 绑定按钮点击事件
                $(this).off('click.upload').on('click.upload', function(e) {
                    e.preventDefault();
                    $('#' + fieldId + 'File').click();
                });
                
                // 绑定文件选择事件
                fileInput.off('change.upload').on('change.upload', function(e) {
                    var file = e.target.files[0];
                    if (!file) return;
                    
                    // 检查文件大小
                    if (file.size > 2 * 1024 * 1024) {
                        layer.msg('图片大小不能超过2MB', {icon: 2});
                        return;
                    }
                    
                    // 创建FormData
                    var formData = new FormData();
                    formData.append('file', file);
                    
                    // 显示加载提示
                    layer.load(1, {shade: [0.3, '#000']});
                    
                    // 发送上传请求
                    $.ajax({
                        url: 'http://localhost:8004/api/upload',
                        type: 'POST',
                        data: formData,
                        processData: false,
                        contentType: false,
                        success: function(res) {
                            layer.closeAll('loading');
                            if (res.success) {
                                var urlInput = $('#' + fieldId + 'Url');
                                var preview = $('#' + fieldId + 'Preview');
                                var text = $('#' + fieldId + 'Text');
                                
                                // 使用返回的文件URL
                                var fileUrl = res.file.url;
                                urlInput.val(fileUrl);
                                preview.attr('src', 'http://localhost:8004' + fileUrl).show();
                                text.html('<span style="color: #5FB878;">上传成功</span>');
                                
                                layer.msg('上传成功', {icon: 1});
                            } else {
                                layer.msg('上传失败：' + (res.message || '未知错误'), {icon: 2});
                            }
                        },
                        error: function() {
                            layer.closeAll('loading');
                            layer.msg('上传失败', {icon: 2});
                        }
                    });
                    
                    // 清空文件输入框
                    e.target.value = '';
                });
            });
        }
        
        // 页面加载时初始化上传功能
        initImageUpload();

        // 图片预览功能
        function showImagePreview(url, title) {
            if (url) {
                // 确保URL是完整的
                var fullUrl = url.startsWith('http') ? url : 'http://localhost:8004' + url;
                layer.photos({
                    photos: {
                        "title": title,
                        "id": 1,
                        "data": [{
                            "src": fullUrl,
                            "alt": title
                        }]
                    }
                });
            }
        }

                    // 为所有图片添加点击预览功能
            $('.layui-upload-img').on('click', function() {
                var src = $(this).attr('src');
                var title = $(this).attr('alt') || '图片预览';
                if (src) {
                    showImagePreview(src, title);
                }
            });

            // 端口号输入限制：只允许输入数字
            $('input[name="mainPort"], input[name="subPort"]').on('input', function() {
                var value = $(this).val();
                // 移除非数字字符
                value = value.replace(/[^\d]/g, '');
                // 限制范围在1-65535
                   // if (value && parseInt(value) > 65535) {
                   //     value = '65535';
                   // }
                $(this).val(value);
            });

            // 企业统一社会信用代码输入限制：只允许输入数字和大写字母
            $('input[name="companyUscc"]').on('input', function() {
                var value = $(this).val();
                // 转换为大写并移除非数字和非字母字符
                value = value.toUpperCase().replace(/[^0-9A-Z]/g, '');
                $(this).val(value);
            });
        });
    </script>

</body>
</html>
